Es importante ajustar el directorio de trabajo para poder cargar datos y exportar las salidas grƔficas.
GISCO es un repositorio abierto de datos geoespaciales que incluye varios conjuntos de datos como paĆses, lĆneas costeras, etiquetas o niveles NUTS. Los conjuntos de datos se proporcionan normalmente en varios niveles de resolución (60M/20M/10M/03M/01M) y en 3 proyecciones diferentes (4326/3035/3857).
Tenga en cuenta que el paquete no proporciona metadatos sobre los archivos descargados, la información estÔ disponible en la pÔgina web API webpage.
PƔgina completa con ejemplos y viƱetas en https://ropengov.github.io/giscoR/
Buscar información para extraer lĆmites administrativos:
Extraer lĆmites administrativos de Chile.
getData()
del paquete raster.WorldClim es una base de datos de alta resolución espacial de datos meteorológicos y climĆ”ticos mundiales. Puede descargar datos meteorológicos y climĆ”ticos de cuadrĆcula para históricos (casi actual) y futuros.
Hay datos climĆ”ticos mensuales de temperatura mĆnima, media y mĆ”xima precipitación, radiación solar, velocidad del viento, presión de vapor de agua y precipitaciones totales.
chile.tmin <- worldclim_country(country = "Chile", var = "tmin",
path = ("data/climatic"))
terra::plot(mean(chile.tmin), plg = list(title ="Temperatura Minima Anual (C)"))chile.bios <- worldclim_country(country = "Chile", var = "bio",
path = ("data/climatic"))
terra::plot(chile.bios)soil <- soil_world(var = c("nitrogen", "ocd", "phh2o", "sand", "silt"),
depth = 60, path = "data/climatic")
chile.soil <- crop(soil,chile)
terra::plot(chile.soil)chile.elevacion <- elevation_30s(country="Chile", path=("data/elevation"),
mask = TRUE)
terra::plot(chile.elevacion)#chile_elevacion2 <- get_elev_raster(locations = chile, z = 9,
# clip = "locations", neg_to_na = TRUE,
# override_size_check = TRUE)
#writeRaster(chile_elevacion2, "data/elevation/CHL_elv_9.tif")
chile_elevacion2 <- rast("data/elevation/CHL_elv_9.tif")
terra::plot(chile_elevacion2)Stadia Maps ofrece recursos cartogrƔficos de varios estilos, incluidos los actualizados tiles from Stamen Design. Se requiere una clave API.
revisar:
registrarse y hay un nivel gratuito para uso no comercial. Una vez
que tengas tu clave API, invoca el registro función:
register_stadiamaps(«YOUR-API-KEY», write = F).
#Reemplaza con tu clave API
#??register_stadiamaps
#https://client.stadiamaps.com/signup/
register_stadiamaps(key = "08ae447c-604f-412c-b523-a8e693f21c20")
#register_stadiamaps(key = "TU-API-AQUI")bbox <- c(left = -80, bottom = -60, right = -65, top = -15)
map <- get_stadiamap(bbox, zoom = 8, maptype = "stamen_terrain_background",
where = "data/layers") ## ā¹ Ā© Stadia Maps Ā© Stamen Design Ā© OpenMapTiles Ā© OpenStreetMap contributors.
## ā¹ 484 tiles needed, this may take a while (try a smaller zoom?)
## Warning: plotting the first 9 out of 121 attributes; use max.plot = 121 to plot
## all
## Warning: plotting the first 10 out of 168 attributes; use max.plot = 168 to
## plot all
raw.map <- plot.data %>%
ggplot() +
geom_sf(data = regions, colour = "white", fill = "gray40") +
geom_point(aes(x = Longitude, y = Latitude, color = Species.name),
alpha = 0.5) +
labs(color = "Species") +
xlim(-77, -66) +
theme_bw() +
scale_size_area()
print(raw.map)adj.map <- plot.data %>%
ggplot() +
geom_sf(data = regions, color = "white", fill = "gray40") +
geom_point(aes(x = Longitude, y = Latitude, color = Species.name),
alpha = 0.5) +
labs(color = "Species") +
xlim(-74, -70) +
ylim(-35.5, -28.5) +
theme_test() +
guides(size = "none") +
annotation_scale(location = "bl") +
annotation_north_arrow(pad_y = unit(0.7, "cm"), pad_x = unit(0.6, "cm"),
height = unit(1, "cm"), width = unit(1, "cm"),
which_north = "T")
print(adj.map)inset <- ggplot(data = SurAmerica) +
geom_sf(color = "gray40", fill = "gray40") +
annotate("rect", xmin = -72, xmax = -69, ymin = -25.5, ymax = -28.5, color = "red", fill = NA) +
xlim(-80, -36) +
labs(x = NULL, y = NULL) +
theme_test() +
theme(axis.text = element_blank(), axis.ticks = element_blank(),
axis.ticks.length = unit(0, "pt"), axis.title = element_blank(),
plot.margin = margin(0, 0, 0, 0, "cm"))
print(inset)regiones <- ne_states(country = "Chile", returnclass = "sf")
SurAmerica <- ne_countries(continent = "South America", returnclass = "sf")chile.elevacion <- elevation_30s(country="Chile", path=("data/elevation"),
mask = TRUE)
names(chile.elevacion) <- "elv"
terra::plot(chile.elevacion)#ajustar en caso de que el dem tenga valores negativos
chile.elevacion <- chile.elevacion %>%
mutate(elv = pmax(0, elv))
terra::plot(chile.elevacion)#limites del raster
#
elv_limits <- minmax(elv) %>% as.vector()
# rounded to lower and upper 500
elv_limits <- c(floor(elv_limits[1] / 500), ceiling(elv_limits[2] / 500)) * 500
# min value = 0.
elv_limits <- pmax(elv_limits, 0)
# Comparar
minmax(elv) %>% as.vector()## [1] 0 5497
## [1] 0 5500
#plot dem
grad <- hypso.colors(10)
dem.plot<- autoplot(elv) +
scale_fill_gradientn(colours = grad, na.value = NA)## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.
terra::terrain() y terra::shade().slope <- terrain(elv, "slope", unit = "radians")
aspect <- terrain(elv, "aspect", unit = "radians")
hill <- shade(slope, aspect, 0, 90)
names(hill) <- "shades"
# Sombreado
pal_greys <- hcl.colors(1000, "Grays")
hillshade <- ggplot() +
geom_spatraster(data = hill) +
scale_fill_gradientn(colors = pal_greys, na.value = NA)
print(hillshade)pal_greys <- hcl.colors(1000, "Grays")
index <- hill %>%
mutate(index_col = rescale(shades, to = c(1, length(pal_greys)))) %>%
mutate(index_col = round(index_col)) %>% pull(index_col)
vector_cols <- pal_greys[index]
hill_plot <- ggplot() +
geom_spatraster(data = hill, fill = vector_cols, maxcell = Inf, alpha = 1)
print(hill_plot)base_plot <- hill_plot +
geom_spatraster(data = elv, maxcell = Inf) +
scale_fill_hypso_tint_c(
limits = elv_limits,
palette = "dem_screen",
alpha = 0.5,
labels = label_comma())
print(base_plot)base_text_size <- 10
base.map <- base_plot +
guides(fill = guide_legend(title = " Altitude m.",
direction = "vertical",
keywidth = 1,
keyheight = 1,
label.position = "right",
title.position = "top",
override.aes = list(alpha = 0.5))) +
labs(x="Longitude", y="Latitude") +
theme_minimal() +
theme(plot.background = element_rect("grey97", colour = NA),
plot.margin = margin(20, 20, 20, 20),
plot.caption = element_text(size = base_text_size * 0.5),
plot.title = element_text(face = "bold", size = base_text_size * 0.9),
axis.text = element_text(size = base_text_size),
legend.position = "right",
legend.title = element_text(size = base_text_size * 0.8),
legend.text = element_text(size = base_text_size * 0.8),
legend.key = element_rect("grey50"),
legend.spacing.x = unit(2, "pt"))
print(base.map)occ.data <- occ.data %>% mutate(Species.name = gsub("_", ". ", Species))
palma.occs <- subset(occ.data, Species == "J_chilensis")
head(palma.occs)species.plot <- base.map +
geom_point(data = palma.occs, aes(x = Longitude, y = Latitude),
alpha = 0.5, colour= "gray20", size=2.5) +
geom_point(data = palma.occs, aes(x = Longitude, y = Latitude, colour = Species.name),
colour = "deeppink", alpha = 0.75, size=2) +
annotation_scale(location = "bl") +
annotation_north_arrow(pad_y = unit(0.7, "cm"),
pad_x = unit(0.6, "cm"),
height = unit(1, "cm"),
width = unit(1, "cm"),
which_north = "T")
print(species.plot)inset <- ggplot(data = SurAmerica) +
geom_sf(color = "gray40", fill = "gray40") +
annotate("rect", xmin = -72, xmax = -69, ymin = -25.5, ymax = -28.5, color = "red", fill = NA) + xlim(-80, -36) +
labs(x = NULL, y = NULL) +
theme_void() +
theme(panel.background = element_rect(fill = "transparent", color = NA),
plot.background = element_rect(fill = "transparent", color = NA),
axis.text = element_blank(),
axis.ticks = element_blank(),
axis.ticks.length = unit(0, "pt"),
axis.title = element_blank(),
plot.margin = margin(0, 0, 0, 0, "cm"))
print(inset)